﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using CrystalDecisions.CrystalReports.Engine;

namespace sccf.Views
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            coso_reporte(0);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            coso_reporte(Convert.ToInt16(TextBox1.Text));
        }


        public void coso_reporte( int coso)
        {
            var conn = new SqlConnection(Vars.connectionString);
            try
            {
                using (var comando = new SqlCommand("ReportePuntosxConsejo", conn))
                {
                    comando.CommandType = System.Data.CommandType.StoredProcedure;
                    SqlParameter id = new SqlParameter("@IdConv", coso);
                    comando.Parameters.Add(id);
                    using (var adaptador = new SqlDataAdapter(comando))
                    {
                        var ds = new DataSet();
                        adaptador.Fill(ds);

                        var reporte = new ReportDocument();
                        reporte.Load(Server.MapPath("Reportes/CrystalReport1.rpt"));
                        reporte.SetDataSource(ds.Tables[0]);
                        reporte.DataSourceConnections[0].SetConnection("Jesus-PC", "SCCF", true);
                        CrystalReportViewer1.ReportSource = reporte;
                    } // end using adaptador
                } // end using comando
            } // end try
            catch (Exception ex)
            {
                WebMsgBox.Show(ex.Message);
            }
            finally
            {
                if (conn.State != ConnectionState.Closed)
                    conn.Close();
                conn.Dispose();
            }
        }
    }
}